﻿<script type="text/javascript">
    var Assign = {};
    var roleId;
    $(function () {
        roleId = $(top.document).find("#hidId").val();
        com.ajax({
            url: "/Logic/BD/UserAjax.aspx?method=GetUserLinkTree",
            type: "POST",
            data: { Id: roleId },
            success: function (data) {
                LoadTree(data);
            }
        });

    });

    function LoadTree(r) {

        var rJson = JSON.parse(r);
        for (var i = 0; i < rJson.length; i++) {
            $("<div class='fitAssignPer'><ul id='tt" + i + "' ></ul></div>").appendTo(("#divUl"));
            console.log($("#tt" + i));
            var arr = [rJson[i]];
            $('#tt' + i).tree({
                data: arr,
                checkbox: true,
                lines: true,
                cascadeCheck: false
            });
        }
    }



    Assign.Cancel = function () {
        $("#assignUserDiv").dialog('close');
    }

    Assign.Confirm = function () {
        var nodeIds = "";
        //1.获取所有的树
        var $trees = $(".fitAssignPer > ul");
        //2.遍历所有数
        for (var i = 0; i < $trees.length; i++) {
            var nodes = $($trees[i]).tree("getChecked");
            var nodes2 = $($trees[i]).tree("getChecked", "indeterminate");
            nodes = nodes.concat(nodes2);
            for (var j = 0; j < nodes.length; j++) {
                nodeIds += nodes[j].id + ",";
            }
        }
        com.ajax({
            url: "/Logic/BD/UserAjax.aspx?method=EditUserLinkTree",
            data: { Id: roleId, PermIds: nodeIds },
            success: function (data) {
                com.message(data.state, data.msg, function () {
                    $("#assignUserDiv").dialog('close');
                })
            }
        });
    }
</script>
<div id="divUl" style="height: 220px; width: 100%; overflow: auto">
   
</div>
<div class="dialog-bottom">
    <input type="hidden" id="hidAddRole.Action" />
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="Assign.Confirm()">确定</a>
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="Assign.Cancel()">取消</a>
</div>
